package com.mh.mh.netty.protocal.endecoder;

/**
 * 通用工具类
 * @author Administrator
 */
public class CommonTools {

    public static final int FIXEDLENGTHFRAME_LENGTH = 256;

    /**
     * 生成指定长度的字符串，不足位右补空格，否则返回原字符串
     * @param str
     * @param assignlength
     * @return
     */
    public static String formatString(String str, int assignlength){
        int intStrlen = 0;
        if(str != null){
            intStrlen = str.length();
        }

        if(intStrlen >= assignlength){// 如果指定长度和字符串长度一致，直接返回原字符串
            return str;
        }else {
            String strSpace = "";
            for(int i = 0, num = assignlength - intStrlen; i < num; i++){
                strSpace = strSpace + " ";
            }
            return str + strSpace;
        }



    }


}
